#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
// 边的结构体
struct EDGE
{
	int nxt, val, to; // 下一个节点，边的权值，边的终点
} edge[N];

int head[N], cnt, n, m;
void init()
{
	memset(head, -1, sizeof(head));
}
void add(int x, int y, int z)
{
	edge[++cnt].val = z;
	edge[cnt].to = y;
	edge[cnt].nxt = head[x];
	head[x] = cnt;
}
int main()
{
	init();
	cin >> n >> m;
	while (m--)
	{
		int x, y, z;
		cin >> x >> y >> z;
		add(x, y, z);
	}
	for (int i = 1; i <= n; i++)
	{
		int maxID = 0, maxVal = 0;
		for (int j = head[i]; ~j; j = edge[j].nxt)
		{
			if (edge[j].val > maxVal)
			{
				maxID = edge[j].to;
				maxVal = edge[j].val;
			}
		}
		if (maxVal)
			cout << maxID << " " << maxVal;
		else
			cout << 0;
		cout << endl;
	}
	return 0;
}